//
//  JYTNavgationBaseViewController.m
//  JYT_IOS
//
//  Created by nxa-tankeke on 16/12/14.
//  Copyright © 2016年 nxa-yuanguoxiang. All rights reserved.
//

#import "JYTNavgationBaseViewController.h"
#define CURRENT_CLASS_NAME [NSString stringWithUTF8String:object_getClassName(self)]

@interface JYTNavgationBaseViewController ()<ProtocolViewControllerContainer, ProtocolBaseHeadEvent>
{
    UIImageView *headImageView;
    UIButton *goNextBtn;
    UILabel *titleLab;
    JYTBaseHeadView *headView;
}
@end

@implementation JYTNavgationBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self addNavigationBarView];
    
    [self isRootViewController];
    [self.view setBackgroundColor:[UIColor colorWithWhite:237/255.0f alpha:1]];
    
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    [self.tabBarView setHidden:NO];
}

- (void) addNavigationBarView
{
    headView = [[JYTBaseHeadView alloc] init];
    headView.delegate = self;
    [self.view addSubview:headView];
    
    CGFloat navBarTobottom = CURRENT_SCREEN_HEIGHT - NAVIGATION_BAR_HEIGHT - STATUS_BAR_HEIGHT;
    
    UIEdgeInsets padding = UIEdgeInsetsMake(0, 0, navBarTobottom, 0);
    
    [headView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view).with.insets(padding);
    }];
}

- (void) setNavgationBarView:(NSDictionary *)dic
{
    [headView setNavgationBarWithDic:dic];
}

- (void)goToNextViewController
{
    MyLog(@"nva  未实现");
    //[self goToNextViewController];
}

- (BOOL) isRootViewController
{
    NSString *name = CURRENT_CLASS_NAME;
    Class c = NSClassFromString(name);
    if ([c isSubclassOfClass:self.class]) {
        MyLog(@"current is root class");
        
    } else {
        MyLog(@"current is not root class");
        
    }
    
    return YES;
}


- (void)pushViewControllerToContainer:(JYTBaseViewController *)bvc
{
    [self.tabBarView setHidden:YES];
    bvc.containerDelegate = self;
    [self.navigationController pushViewController:bvc animated:YES];
    
}

- (void)popViewControllerFromContainer
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void) PopToRootViewController
{
    if (self.navigationController) {
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
}

- (void) PopToExactViewController:(JYTBaseViewController *)bvc
{
    if (bvc && self.navigationController) {
        [self.navigationController popToViewController:bvc animated:YES];
    }
    
}


- (void)clickLeftBtn
{
    [self popViewControllerFromContainer];
}

- (void)clickRightBtn{
    [self goToNextViewController];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
